package paritclecontainer2d;

import java.awt.Color;
import java.awt.Graphics;

public class ColoredParticle extends Particle{

	
	protected int width;
	protected int height;
	protected boolean fill;
	protected Color color;
	
	public ColoredParticle(Color color, double timeToLife, int width, int height, boolean fill) {

		this.color = color;
		this.initialTTL = timeToLife;
		this.ttl = timeToLife;
		
		this.width = width;
		this.height = height;
		this.fill = fill;
	}

	public ColoredParticle(Color color, double timeToLife, int width, int height) {
		this(color,timeToLife,width,height,false);
	}
	
	public void setColor(Color color){
		this.color = color;
	}
	
	public Color getColor(){
		return color;
	}
	
	
	public void paintComponent(Graphics arg) {	
		
		double alpha = (((double)ttl/(double)initialTTL)*255);
			
		arg.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(), (int) alpha));

		
		if(!fill){
			arg.drawRect(x, y, width, height);
		}
		else{
			arg.fillRect(x, y, width, height);
		}
		
	}


	@Override
	public Object clone() throws CloneNotSupportedException {
		return new ColoredParticle(color,ttl,width,height,fill);
	}


	
}
